/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tabela.java
 *
 * Created on 24/04/2013, 19:19:25
 */
package gui;

import java.util.ArrayList;
import visual.ontogrator.pkg2.Gene;

/**
 *
 * @author Gabriel
 */
public class Tabela extends javax.swing.JFrame {
    static ArrayList<Gene> agene = new ArrayList<Gene>();
   /** Creates new form Tabela */
    public Tabela(ArrayList<Gene> agene) {
        initComponents();
        tabela(agene);
        
    }

   

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Table (Salvar como .csv)");
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 300));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setPreferredSize(new java.awt.Dimension(300, 300));
        jScrollPane1.setViewportView(jTextArea1);

        getContentPane().add(jScrollPane1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    private void tabela(ArrayList<Gene> agene){
        Gene g = new Gene();
        String allinfo="";
        String linha="\n";
        String espaco=" - ";
        //String coluna="\t";
        String coluna=";";
        
        String aux="";
        //imprimir cabeçalho
        allinfo = imprimirPontoVirgula(g.getArrayTitulo(),coluna)+coluna+"Nome_Lista"+linha;
       
         for(int i=0;i<agene.size();i++){
             
             aux = agene.get(i).getNome_Lista();
             for(int j=0;j<agene.get(i).getArrayInfo().size();j++){
                aux = imprimirPontoVirgula((ArrayList<String>)agene.get(i).getArrayInfo().get(j), espaco)+coluna+aux;
             }
           allinfo = allinfo+"\n"+aux;
        }
        jTextArea1.setText(allinfo);
        //System.out.println(allinfo);
    }
     
    private static String imprimirPontoVirgula(ArrayList<String> vetor, String delimiter) {
        String info="";
        try{
        info = vetor.get(0);
        for (int i = 1; i < vetor.size(); i++) {
            info = vetor.get(i)+ delimiter + info;
        }
        }catch(Exception e){
            
        }
        return info;
    }
    
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tabela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tabela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tabela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tabela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Tabela(agene).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}
